﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.zynga.skelly.util.color {
    import flash.filters.*;

    public class ColorMatrix {

        private static var r_lum:Number = 0.212671;
        private static var g_lum:Number = 0.71516;
        private static var b_lum:Number = 0.072169;
        private static var IDENTITY:Array = new Array(1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0);

        public var matrix:Array;

        public function ColorMatrix(_arg1:Object=null){
            if ((_arg1 is ColorMatrix)){
                this.matrix = _arg1.matrix.concat();
            } else {
                if ((_arg1 is Array)){
                    this.matrix = _arg1.concat();
                } else {
                    this.reset();
                };
            };
        }
        public function reset():void{
            this.matrix = IDENTITY.concat();
        }
        public function clone():ColorMatrix{
            return (new ColorMatrix(this.matrix));
        }
        public function adjustSaturation(_arg1:Number):void{
            var _local2:Number = (1 - _arg1);
            var _local3:Number = (_local2 * r_lum);
            var _local4:Number = (_local2 * g_lum);
            var _local5:Number = (_local2 * b_lum);
            var _local6:Array = new Array((_local3 + _arg1), _local4, _local5, 0, 0, _local3, (_local4 + _arg1), _local5, 0, 0, _local3, _local4, (_local5 + _arg1), 0, 0, 0, 0, 0, 1, 0);
            this.concat(_local6);
        }
        public function adjustContrast(_arg1:Number, _arg2:Number=undefined, _arg3:Number=undefined):void{
            _arg2 = ((_arg2) || (_arg1));
            _arg3 = ((_arg3) || (_arg1));
            _arg1 = (_arg1 + 1);
            _arg2 = (_arg2 + 1);
            _arg3 = (_arg3 + 1);
            var _local4:Array = new Array(_arg1, 0, 0, 0, (128 * (1 - _arg1)), 0, _arg2, 0, 0, (128 * (1 - _arg2)), 0, 0, _arg3, 0, (128 * (1 - _arg3)), 0, 0, 0, 1, 0);
            this.concat(_local4);
        }
        public function adjustBrightness(_arg1:Number, _arg2:Number=undefined, _arg3:Number=undefined):void{
            _arg2 = ((_arg2) || (_arg1));
            _arg3 = ((_arg3) || (_arg1));
            var _local4:Array = new Array(1, 0, 0, 0, _arg1, 0, 1, 0, 0, _arg2, 0, 0, 1, 0, _arg3, 0, 0, 0, 1, 0);
            this.concat(_local4);
        }
        public function adjustHue(_arg1:Number):void{
            _arg1 = (_arg1 * (Math.PI / 180));
            var _local2:Number = Math.cos(_arg1);
            var _local3:Number = Math.sin(_arg1);
            var _local4:Number = 0.213;
            var _local5:Number = 0.715;
            var _local6:Number = 0.072;
            var _local7:Array = new Array(((_local4 + (_local2 * (1 - _local4))) + (_local3 * -(_local4))), ((_local5 + (_local2 * -(_local5))) + (_local3 * -(_local5))), ((_local6 + (_local2 * -(_local6))) + (_local3 * (1 - _local6))), 0, 0, ((_local4 + (_local2 * -(_local4))) + (_local3 * 0.143)), ((_local5 + (_local2 * (1 - _local5))) + (_local3 * 0.14)), ((_local6 + (_local2 * -(_local6))) + (_local3 * -0.283)), 0, 0, ((_local4 + (_local2 * -(_local4))) + (_local3 * -((1 - _local4)))), ((_local5 + (_local2 * -(_local5))) + (_local3 * _local5)), ((_local6 + (_local2 * (1 - _local6))) + (_local3 * _local6)), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1);
            this.concat(_local7);
        }
        public function colorize(_arg1:Number, _arg2:Number):void{
            var _local3:Number = (((_arg1 >> 16) & 0xFF) / 0xFF);
            var _local4:Number = (((_arg1 >> 8) & 0xFF) / 0xFF);
            var _local5:Number = ((_arg1 & 0xFF) / 0xFF);
            if (isNaN(_arg2)){
                _arg2 = 1;
            };
            var _local6:Number = (1 - _arg2);
            var _local7:Array = new Array((_local6 + ((_arg2 * _local3) * r_lum)), ((_arg2 * _local3) * g_lum), ((_arg2 * _local3) * b_lum), 0, 0, ((_arg2 * _local4) * r_lum), (_local6 + ((_arg2 * _local4) * g_lum)), ((_arg2 * _local4) * b_lum), 0, 0, ((_arg2 * _local5) * r_lum), ((_arg2 * _local5) * g_lum), (_local6 + ((_arg2 * _local5) * b_lum)), 0, 0, 0, 0, 0, 1, 0);
            this.concat(_local7);
        }
        public function setAlpha(_arg1:Number):void{
            var _local2:Array = new Array(1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, _arg1, 0);
            this.concat(_local2);
        }
        public function desaturate():void{
            var _local1:Array = new Array(r_lum, g_lum, b_lum, 0, 0, r_lum, g_lum, b_lum, 0, 0, r_lum, g_lum, b_lum, 0, 0, 0, 0, 0, 1, 0);
            this.concat(_local1);
        }
        public function invert():void{
            var _local1:Array = new Array(-1, 0, 0, 0, 0xFF, 0, -1, 0, 0, 0xFF, 0, 0, -1, 0, 0xFF, 0, 0, 0, 1, 0);
            this.concat(_local1);
        }
        public function threshold(_arg1:Number):void{
            var _local2:Array = new Array((r_lum * 0x0100), (g_lum * 0x0100), (b_lum * 0x0100), 0, (-256 * _arg1), (r_lum * 0x0100), (g_lum * 0x0100), (b_lum * 0x0100), 0, (-256 * _arg1), (r_lum * 0x0100), (g_lum * 0x0100), (b_lum * 0x0100), 0, (-256 * _arg1), 0, 0, 0, 1, 0);
            this.concat(_local2);
        }
        public function randomize(_arg1:Number):void{
            if (isNaN(_arg1)){
                _arg1 = 1;
            };
            var _local2:Number = (1 - _arg1);
            var _local3:Number = (_local2 + (_arg1 * (Math.random() - Math.random())));
            var _local4:Number = (_arg1 * (Math.random() - Math.random()));
            var _local5:Number = (_arg1 * (Math.random() - Math.random()));
            var _local6:Number = ((_arg1 * 0xFF) * (Math.random() - Math.random()));
            var _local7:Number = (_arg1 * (Math.random() - Math.random()));
            var _local8:Number = (_local2 + (_arg1 * (Math.random() - Math.random())));
            var _local9:Number = (_arg1 * (Math.random() - Math.random()));
            var _local10:Number = ((_arg1 * 0xFF) * (Math.random() - Math.random()));
            var _local11:Number = (_arg1 * (Math.random() - Math.random()));
            var _local12:Number = (_arg1 * (Math.random() - Math.random()));
            var _local13:Number = (_local2 + (_arg1 * (Math.random() - Math.random())));
            var _local14:Number = ((_arg1 * 0xFF) * (Math.random() - Math.random()));
            var _local15:Array = new Array(_local3, _local4, _local5, 0, _local6, _local7, _local8, _local9, 0, _local10, _local11, _local12, _local13, 0, _local14, 0, 0, 0, 1, 0);
            this.concat(_local15);
        }
        public function setChannels(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number):void{
            var _local5:Number = ((((((_arg1 & 1) == 1)) ? 1 : 0 + (((_arg1 & 2) == 2)) ? 1 : 0) + (((_arg1 & 4) == 4)) ? 1 : 0) + (((_arg1 & 8) == 8)) ? 1 : 0);
            if (_local5 > 0){
                _local5 = (1 / _local5);
            };
            var _local6:Number = ((((((_arg2 & 1) == 1)) ? 1 : 0 + (((_arg2 & 2) == 2)) ? 1 : 0) + (((_arg2 & 4) == 4)) ? 1 : 0) + (((_arg2 & 8) == 8)) ? 1 : 0);
            if (_local6 > 0){
                _local6 = (1 / _local6);
            };
            var _local7:Number = ((((((_arg3 & 1) == 1)) ? 1 : 0 + (((_arg3 & 2) == 2)) ? 1 : 0) + (((_arg3 & 4) == 4)) ? 1 : 0) + (((_arg3 & 8) == 8)) ? 1 : 0);
            if (_local7 > 0){
                _local7 = (1 / _local7);
            };
            var _local8:Number = ((((((_arg4 & 1) == 1)) ? 1 : 0 + (((_arg4 & 2) == 2)) ? 1 : 0) + (((_arg4 & 4) == 4)) ? 1 : 0) + (((_arg4 & 8) == 8)) ? 1 : 0);
            if (_local8 > 0){
                _local8 = (1 / _local8);
            };
            var _local9:Array = new Array((((_arg1 & 1) == 1)) ? _local5 : 0, (((_arg1 & 2) == 2)) ? _local5 : 0, (((_arg1 & 4) == 4)) ? _local5 : 0, (((_arg1 & 8) == 8)) ? _local5 : 0, 0, (((_arg2 & 1) == 1)) ? _local6 : 0, (((_arg2 & 2) == 2)) ? _local6 : 0, (((_arg2 & 4) == 4)) ? _local6 : 0, (((_arg2 & 8) == 8)) ? _local6 : 0, 0, (((_arg3 & 1) == 1)) ? _local7 : 0, (((_arg3 & 2) == 2)) ? _local7 : 0, (((_arg3 & 4) == 4)) ? _local7 : 0, (((_arg3 & 8) == 8)) ? _local7 : 0, 0, (((_arg4 & 1) == 1)) ? _local8 : 0, (((_arg4 & 2) == 2)) ? _local8 : 0, (((_arg4 & 4) == 4)) ? _local8 : 0, (((_arg4 & 8) == 8)) ? _local8 : 0, 0);
            this.concat(_local9);
        }
        public function blend(_arg1:ColorMatrix, _arg2:Number):void{
            var _local3:Number = (1 - _arg2);
            var _local4:Number = 0;
            while (_local4 < 20) {
                this.matrix[_local4] = ((_local3 * this.matrix[_local4]) + (_arg2 * _arg1.matrix[_local4]));
                _local4++;
            };
        }
        public function concat(_arg1:Array):void{
            var _local5:Number;
            var _local2:Array = new Array();
            var _local3:Number = 0;
            var _local4:Number = 0;
            while (_local4 < 4) {
                _local5 = 0;
                while (_local5 < 5) {
                    _local2[(_local3 + _local5)] = (((((_arg1[_local3] * this.matrix[_local5]) + (_arg1[(_local3 + 1)] * this.matrix[(_local5 + 5)])) + (_arg1[(_local3 + 2)] * this.matrix[(_local5 + 10)])) + (_arg1[(_local3 + 3)] * this.matrix[(_local5 + 15)])) + ((_local5 == 4)) ? _arg1[(_local3 + 4)] : 0);
                    _local5++;
                };
                _local3 = (_local3 + 5);
                _local4++;
            };
            this.matrix = _local2;
        }
        public function get filter():ColorMatrixFilter{
            return (new ColorMatrixFilter(this.matrix));
        }

    }
}//package com.zynga.skelly.util.color 
